// $codepro.audit.disable hidingInheritedFields
/**
 * License under GNU's GPL 
 * Patient.java 
 */


// $codepro.audit.disable com.instantiations.eclipse.analysis.audit.security.incompatibleTypesStoredInACollection, numericLiterals

import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.FileHandler;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Class represents a Patient
 * 
 * @author Team 9
 * @version 1.0
 * 
 */
public class Patient extends User {
	/**
	 * GUI for patient
	 */
	private PatientGui window;

	/**
	 * type of object
	 */
	private int type = 3;
	
	/**
	 * Logger variable
	 */
	public static String Fn;

	/**
	 * Logger variable
	 */
	public static String Ln;

	/**
	 * Logger variable
	 */
	// Logging code
	private static final Logger PATIENTLOGGER = Logger.getLogger("Patient");

	static {
		FileHandler filehand = null;
		try {
			filehand = new FileHandler("Patient.log");
		} catch (SecurityException se) {
			PATIENTLOGGER.log(Level.SEVERE,
					"Security Exception creating the logger", se);
			se.printStackTrace();
		} catch (IOException ioe) {
			PATIENTLOGGER.log(Level.SEVERE, "IO Exception creating the logger",
					ioe);
			ioe.printStackTrace();
		}

		filehand.setFilter(new Filter() {
			public boolean isLoggable(LogRecord record) {
				return true;
			}
		});
		PATIENTLOGGER.addHandler(filehand);
		PATIENTLOGGER.setLevel(Level.ALL);
	}// end logging code

	/**
	 * Overrides the toString() method to print the appropriate instance
	 * variables
	 * 
	 * @return String to be printed
	 */
	@Override
	public String toString() {
		return "Patient [setAppointment=" + setAppointment + ", appointment="
				+ appointment + ", lastName=" + lastName + ", firstName="
				+ firstName + ", userName=" + userName + ", suspend=" + suspend
				+ "]";
	}

	/**
	 * Arraylist to hold all the treatment records for the patient
	 */
	private final List<TreatmentRecord> records;

	/**
	 * String to hold the appointment details
	 */
	private String setAppointment = "You do not have an appoitment set up."; // check

	/**
	 * Constructor for the class
	 * 
	 * @param first
	 *            value for firstName
	 * @param last
	 *            value for lastName
	 * @param user
	 *            value for userName
	 * @param pass
	 *            value for password
	 */
	public Patient(String first, String last, String user, String pass) {
		lastName = last;
		firstName = first;
		userName = user;
		password = pass;
		suspend = false;
		type = 3;
		records = new ArrayList<TreatmentRecord>();
		PATIENTLOGGER.info("Patient constructed: " + first + " " + last);

	}

	/**
	 * Method to generate a GUI for the patient
	 * 
	 */
	@Override
	public void showGUI() {
		window = new PatientGui(this);
		window.getFrame().setVisible(true);
	}

	/**
	 * Method for the patient to make an appointment
	 */
	public void appointment() {
		final boolean b;
		final Scanner scan = new Scanner(System.in);
		System.out.println("Date Desired");
		final String dateRA = scan.nextLine();
		System.out.println("Time Desired");
		final String timeRA = scan.nextLine();
		System.out.println("Doctor Desired");
		final String doctorRA = scan.nextLine();

		b = appointment.canRequestAppointment(dateRA, timeRA, doctorRA);
		if (b) {
			setAppointment = "Your next appointment is for " + dateRA + " at "
					+ timeRA + " with " + doctorRA + ".";
		}
	}

	/**
	 * Method to add a new treatment records for the patient
	 * 
	 * @param rec
	 *            the records to add
	 */
	public void newTreatmentRecord(TreatmentRecord rec) {
		records.add(rec);
	}

	/**
	 * Getter for treatment records
	 * 
	 * @return records
	 */
	public List<TreatmentRecord> getRecords() {
		return records;
	}

	/**
	 * Method to view all treatment records
	 * @return toReturn string with the record
	 */
	public String viewTreatmentRecord() {
		String toReturn = "";
		final int i = 0;
		final int size = records.size();
		if (i < size) {
			toReturn += records.get(size).getLastName() + "\n";
			toReturn += records.get(size).getFirstName() + "\n";
			toReturn += records.get(size).getAppointment() + "\n";
			toReturn += records.get(size).getAttendingNurse() + "\n";
			toReturn += records.get(size).getChiefComplaint() + "\n";
			toReturn += records.get(size).getVitalSigns() + "\n";
			toReturn += records.get(size).getDiagnosis() + "\n";
			toReturn += records.get(size).getDiagnosis() + "\n";
			toReturn += "Doctors Orders:" + "\n";
			toReturn += records.get(size).getOrders().getPerscriptions() + "\n";
			toReturn += records.get(size).getOrders().getLabWorkPerformed()
					+ "\n";
			toReturn += records.get(size).getOrders().getFollowUp() + "\n";
			toReturn += records.get(size).getOrders().getOtherInstructions()
					+ "\n";
		}

		// final Scanner scan = new Scanner(System.in);
		// System.out.println("Next Treatment Record? Yes or No");
		// final String yesNo = scan.nextLine();
		// if (yesNo.equalsIgnoreCase("Yes")) {
		// i++;
		// }// Way to loop back around???
		return toReturn;
	}
}
